var defaultTitle = 'Truesion shop';
/*
     菜单点击事件
*/
function MainMenuClick(event, treeId, treeNode) {
	 event.preventDefault()
    if (treeNode.isParent) {
        var zTree = $.fn.zTree.getZTreeObj(treeId);
        zTree.expandNode(treeNode);
        MainMenuClick(event, treeId, treeNode.children[0]);  //回调自身
        return ;
    }
    if (treeNode.target && treeNode.target == 'dialog'){
        $(event.target).dialog({id:treeNode.tabid, url:treeNode.url, title:treeNode.name});
    }else{
    	$(event.target).navtab({id:treeNode.tabid, url:treeNode.url, title:treeNode.name, fresh:treeNode.fresh, external:treeNode.external});
    }
}

/*
    上传单图片统一回调
*/
function upload_callback(file, data, ele) {
    data = JSON.parse(data);
    if(data[BJUI.keys.statusCode] == BJUI.statusCode.ok) {
        ele.parents(".parent_img").find('img').attr('src', data.message);
        ele.parents(".parent_img").find('input[type=hidden]').val(data.message);
    }else{
        ele.bjuiajax('ajaxDone', data);
    }
}
/*
* 多上传统一回调,
* 在上传控件的prev上添加 <div class="multimg clearfix" data-name="pol"></div>
* */
function upload_multi_callback(file, data, ele) {
    data = JSON.parse(data);
    if(data[BJUI.keys.statusCode] == BJUI.statusCode.ok) {
        var multimg = ele.parents('.form-group').find('.multimg'),
            name = multimg.attr('data-name');
        multimg.append(function() {
           var odiv = '<div class="pull-left">';
            odiv += '<img src="'+data.message+'" width="70" />';
            odiv += '<input type="hidden" name="'+name+'[]" value="'+data.message+'" />';
            odiv += '<p class="text-center"><a href="javascript:void(0)" class="remove">删除</a></p>'
            odiv += '</div>';
            return odiv;
        });

    }else{
        ele.bjuiajax('ajaxDone', data);
    }
}
/*
    全选操作回调
* */
function callbackRefres(result) {
    if(result[BJUI.keys.statusCode] == BJUI.statusCode.ok){
        $.CurrentNavtab.navtab('refresh');
    }else{
        $(this).bjuiajax('ajaxDone', result);
    }
}
/*
* 弹窗表单回调
* */
function dialogFormCall(result, dobj) {
    if( result[BJUI.keys.statusCode] == BJUI.statusCode.ok ) {
        dobj.dialog('closeCurrent');
        callbackRefres( result );
    }else{
        dobj.bjuiajax('ajaxDone', result);
    }
}
/*
 创建一个dialog
 @param durl {string} dialog面面地址
 @param did {number}  Id
 @param tit {string} title
 @param opt {object} dialog的额外参数
 */
function createDialog(durl, tit, did, opt) {

    if( !durl ) throw new Error("createDialog--创建dialog时,传入了的不正确url");
    tit = tit || defaultTitle;
    did = did || "dialog_" + (new Date().getTime());
    opt = opt || {};
    return $(this).dialog($.extend({id:did, title:tit, mask:true, fresh:true, url:durl}, opt));
}
/*
* 创建一个navtab
* @parem durl {string} navtab url地址
* @param tit {string}  标题
* @param did {string} id, 如果打开一个相同id的navtab,则会作出刷新操作
* @param opt {object} 额外的参数
* */
function createNavtab(durl, tit, did, opt) {
    if (!durl) return new Error('没有传入地址');
   return $(this).navtab($.extend({
       url:durl,
       title:tit || defaultTitle,
       id:did || 'navtab_' + (new Date().getTime()),
       fresh:true
   }, opt || {}));

}